/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package com.company.workflow.loader;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Element;

import com.opensymphony.workflow.InvalidWorkflowDescriptorException;
import com.opensymphony.workflow.loader.ValidationHelper;
import com.opensymphony.workflow.loader.XMLUtil;
import com.opensymphony.workflow.util.Validatable;

/**
 * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
 * @version $Revision: 1.5 $
 */
public class RestrictionDescriptor extends AbstractDescriptor implements
		Validatable {
	// ~ Instance fields
	// ////////////////////////////////////////////////////////

	protected List conditions = new ArrayList();

	// ~ Constructors
	// ///////////////////////////////////////////////////////////

	public RestrictionDescriptor() {
	}

	// ~ Methods
	// ////////////////////////////////////////////////////////////////

	public List getConditions() {
		return conditions;
	}

	public void validate() throws InvalidWorkflowDescriptorException {
		ValidationHelper.validate(conditions);
	}

	public String getXML() {

		if (conditions.size() != 0) {

			StringBuffer buf = new StringBuffer();
			buf.append("<restrict-to>");

			if (conditions.size() > 0) {
				for (int i = 0; i < conditions.size(); i++) {
					ConditionsDescriptor condition = (ConditionsDescriptor) conditions
							.get(i);
					buf.append(condition.getXML());
				}
			}

			buf.append("</restrict-to>");
			return buf.toString();
		} else {
			return "";
		}
	}
}
